﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>TraySetIcon - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The TraySetIcon function changes the script's tray icon to one from the specified file." />
<meta name="ahk:equiv-v1" content="commands/Menu.htm#Icon" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>TraySetIcon</h1>

<p>Changes the script's <a href="../Program.htm#tray-icon">tray icon</a>.</p>

<pre class="Syntax"><span class="func">TraySetIcon</span>(<span class="optional">FileName, IconNumber, Freeze</span>)</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>FileName</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>The path of an icon or image file. For a list of supported formats, 请参阅 <a href="GuiControls.htm#IconSupport">the Picture control</a>.</p>
    <p>Specify an asterisk (*) to restore the script to its default icon.</p>
  </dd>
  
  <dt>IconNumber</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>To use an icon group other than the first one in the file, specify its number for <em>IconNumber</em> (if omitted, it defaults to 1). 例如, <strong>2</strong> would load the default icon from the second icon group. If <em>IconNumber</em> is negative, its absolute value is assumed to be the resource ID of an icon within an executable file.</p>
  </dd>
  
  <dt>Freeze</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#boolean">整数(布尔值)</a></p>
    <p>Specify 1 (true) to freeze the icon, or 0 (false) to unfreeze it (or omit it to keep the frozen/unfrozen state unchanged). When the icon has been frozen, <a href="Pause.htm">Pause</a> and <a href="Suspend.htm">Suspend</a> will not change it. Note: To freeze or unfreeze the <em>current</em> icon, use 1 (true) or 0 (false) as in the following example: <code>TraySetIcon(,, 1)</code>.</p>
  </dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>Changing the tray icon also changes the icon displayed by <a href="InputBox.htm">InputBox</a> and subsequently-created <a href="../objects/Gui.htm">GUI</a> windows. <a href="../Scripts.htm#ahk2exe">Compiled scripts</a> are also affected even if a custom icon was specified at the time of compiling. Note: Changing the icon will not unhide the tray icon if it was previously hidden by means such as <a href="_NoTrayIcon.htm">#NoTrayIcon</a>; to do that, use <code><a href="../Variables.htm#IconHidden">A_IconHidden</a> := false</code>.</p>
<p id="distort">Slight distortion may occur when loading tray icons from file types other than .ICO. This is especially true for 16x16 icons. To prevent this, store the desired tray icon inside a .ICO file.</p>
<p>There are some icons built into the operating system's DLLs and CPLs that might be useful. 例如: <code>TraySetIcon "Shell32.dll", 174</code>.</p>
<p>A <a href="../misc/ImageHandles.htm">bitmap or icon handle</a> can be used instead of a filename. 例如, <code>TraySetIcon "HBITMAP:" handle</code>.</p>
<p>The built-in variables <strong><a href="../Variables.htm#IconNumber">A_IconNumber</a></strong> and <strong><a href="../Variables.htm#IconFile">A_IconFile</a></strong> contain the number and name (with full path) of the current icon (both are blank if the icon is the default).</p>
<p>The tray icon's tooltip can be changed by assigning a value to <a href="../Variables.htm#IconTip">A_IconTip</a>.</p>

<h2 id="Related">相关</h2>
<p><a href="_NoTrayIcon.htm">#NoTrayIcon</a>, <a href="TrayTip.htm">TrayTip</a>, <a href="../objects/Menu.htm">Menu object</a></p>

</body>
</html>